package com.topboya.linker.ui.activity;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.topboya.linker.R;
import com.topboya.linker.diyview.CenteredEditText;
import com.topboya.linker.model.response.SelectFileResponse;
import com.topboya.linker.model.response.VisitTypeResponse;
import com.topboya.linker.ui.adapter.SelectFileAdapter;
import com.topboya.linker.ui.base.activity.BaseActivity;
import com.topboya.linker.ui.presenter.SelectFilePresenter;
import com.topboya.linker.ui.view.SelectFileView;
import com.topboya.linker.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

/*
* 选择资料 比如ppt，视频，音频等
* */
public class SelectFileActivity extends BaseActivity<SelectFileView, SelectFilePresenter> implements SelectFileView {

    private static final String TAG = "SelectFileActivity-";

    private TextView toolbar_title;
    private CenteredEditText search;
    private RecyclerView recycle_display_file;
    private String productId;
    private Button btn_select;
    @Override
    protected int getLayoutId() {

        return R.layout.activity_select_file;
    }

    @Override
    protected void initView() {

        toolbar_title = findViewById(R.id.toolbar_title);
        search = findViewById(R.id.search);
        recycle_display_file = findViewById(R.id.recycle_display_file);
        btn_select = findViewById(R.id.btn_select);
    }

    @Override
    protected void initData() {

        productId = getIntent().getStringExtra("productId");
        LogUtils.v(TAG + "productId:"+productId);
        toolbar_title.setText("资料信息");
        mPresenter.getProductFileList(productId,null);

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected SelectFilePresenter createPresenter() {

        return new SelectFilePresenter(this);
    }


    @Override
    public void getProductFileList( List<SelectFileResponse.FileList> fileLists) {

        LogUtils.v(TAG + "fileList:"+fileLists.toString());
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2);
        recycle_display_file.setLayoutManager(layoutManager);
        SelectFileAdapter selectFileAdapter = new SelectFileAdapter(this,(ArrayList<SelectFileResponse.FileList>) fileLists);
        recycle_display_file.setAdapter(selectFileAdapter);
        selectFileAdapter.setOnItemClickListener((v, position) -> {

//            btn_select.setText("选择（"+count+"）");
        });

        btn_select.setOnClickListener(v -> {

//          ArrayList<SelectFileResponse.FileList> fileListss= selectFileAdapter.getSelectedItem();
//          LogUtils.v(TAG + "fileListss:"+fileListss.toString());
//          backTostartActivity(fileListss);

        });


    }

    private void backTostartActivity( ArrayList<SelectFileResponse.FileList> list) {

        //数据是使用Intent返回
        Intent intent = new Intent();
        //把返回数据存入Intent
        intent.putExtra("result", list);
        //设置返回数据
        setResult(1001, intent);
        //关闭Activity
        finish();
    }

}


